package com.daodao;

import com.daodao.mapper.BrandMapper;
import com.daodao.pojo.Brand;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisDemo {
    public static void main(String[] args) throws IOException {
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        SqlSession sqlSession = sqlSessionFactory.openSession();

//        sqlSession.selectMap()

//        List<Object> res = sqlSession.selectList("com.daodao.mapper.BrandMapper.selectAll");
//        System.out.println(res);

//        List<Brand> res = sqlSession.selectList("com.daodao.mapper.BrandMapper.selectAll");

        BrandMapper brandMapper = sqlSession.getMapper(BrandMapper.class);
        List<Brand> res = brandMapper.selectAll();

        for (Brand br : res) {
            System.out.println(br);
        }
        sqlSession.close();
    }
}
